home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#33 (Jun 88)
/
icon source
/
StdMenu.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1988-03-28
|
3KB
|
146 lines
{
| StdMenu provides standard menu objects.
}
unit StdMenu;
interface
uses MacIntf, StdPoll;
const
{ Standard File menu item numbers }
NewItem = 1;
OpenItem = 2;
CloseItem = 3;
{ ------ }
SaveItem = 5;
SaveAsItem = 6;
RevertItem = 7;
{ ------ }
PageSetupItem = 9;
PrintItem = 10;
{ ------ }
QuitItem = 12;
type
{
| MenuHdlr is the base object for all menus.
| The Create method installs the menu at the end of
| the menu bar. The Choose method should be overridden
| with code to perform a menu choice.
}
MenuHdlr = object
TheMenu : MenuHandle;
procedure Create (RsrcID : Integer);
procedure Choose (Choice : Integer);
end;
{
| AppleMenuHdlr provides all the functionallity of
| a standard Apple menu. It must be Setup with an
| alert id for the About… message before Create is
| called.
}
AppleMenuHdlr = object (MenuHdlr)
AboutID : Integer;
procedure Create (RsrcID : Integer); override;
procedure Choose (Choice : Integer); override;
procedure Setup (AlertID : Integer);
end;
{
| StdFileMenuHdlr is a minimal File menu. The Choose
| method can Close DA's and Quit.
}
StdFileMenuHdlr = object (MenuHdlr)
procedure Choose (Choice : Integer); override;
end;
{
| StdEditMenuHdlr is a minimal Edit menu. The Choose
| method supports DA editing.
}
StdEditMenuHdlr = object (MenuHdlr)
procedure Choose (Choice : Integer); override;
end;
{ ----------------------------------------------------------------------- }
implementation
{
| Generic Menu Handler
}
procedure MenuHdlr.Create (RsrcID : Integer);
begin
{ Read in a standard menu resource.
| Remember: Object variables are Handles! 'Self' is set only
| as you enter the method, so HLock it if you call any
| potential heap-scramblers! }
HLock(Handle(Self));
TheMenu := GetMenu (RsrcID);
InsertMenu (TheMenu, 0);
HUnlock(Handle(Self)) end;
procedure MenuHdlr.Choose (Choice : Integer);
begin end;
{
| Apple Menu Handler
}
procedure AppleMenuHdlr.Create (RsrcID : Integer);
begin
{ Read in the Apple menu stub, and add DA's }
HLock(Handle(Self));
TheMenu := GetMenu (RsrcID);
AddResMenu (TheMenu, 'DRVR');
InsertMenu (TheMenu, 0);
HUnlock(Handle(Self)) end;
procedure AppleMenuHdlr.Choose (Choice : Integer);
var
AccName : Str255;
AccNumber : integer;
begin
{ Post alert or open DA }
if Choice = 1
then AccNumber := Alert (AboutID, NIL)
else begin
GetItem (TheMenu, Choice, AccName);
AccNumber := OpenDeskAcc (AccName) end end;
procedure AppleMenuHdlr.Setup (AlertID : Integer);
begin
AboutID := AlertID end;
{
| Standard File Menu
}
procedure StdFileMenuHdlr.Choose (Choice : Integer);
var
FrontWP : windowPeek;
begin
case Choice of
NewItem : ;
OpenItem : ;
CloseItem : begin { If frontmost window is DA, close it. }
FrontWP := windowPeek(frontWindow);
if FrontWP^.windowKind < 0
then CloseDeskAcc(FrontWP^.windowKind) end;
SaveItem : ;
SaveAsItem : ;
RevertItem : ;
PageSetupItem : ;
PrintItem : ;
QuitItem : Done := true;
otherwise { nothing } end end;
{
| Standard Edit menu
}
procedure StdEditMenuHdlr.Choose (Choice : Integer);
var
Trash : Boolean;
begin
Trash := SystemEdit (Choice-1) end;
end. { of StdMenu unit }